
package astexec

import (
	"asteval"
	"fmt"
	"environ"
)

type Statement interface {
	Execute(env *environ.Environment)
}

type Assignment struct {
	name string
	expr *asteval.Expression
}

func NewAssignment(nm string, ex *asteval.Expression) *Assignment {
	return &Assignment{name: nm, expr: ex}
}

func (a *Assignment) Execute(env *environ.Environment) {
	val := a.expr.Evaluate(env)
	env.Set(a.name, val)
}

type Print struct {
	expr *asteval.Expression
}

func NewPrint(ex *asteval.Expression) *Print {
	return &Print{expr: ex}
}

func (p *Print) Execute(env *environ.Environment) {
	val := p.expr.Evaluate(env)
	fmt.Println(val.String())
}

